package com.javatian.dao;

import com.javatian.entity.OrderInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * 订单信息Dao
 */
@Repository
public interface OrderInfoDao extends Mapper<OrderInfo> {

    /*根据用户id查询订单列表*/
    List<OrderInfo> findByUserId(@Param("userId")Long userId,@Param("level")Integer level);

    /*根据主键id查询单个订单*/
    OrderInfo findById(Long id);

    /*改变订单状态*/
    void updateStatus(@Param("id")Long id,@Param("status")String status);

    /*根据主键id删除某个订单*/
    int deleteById(Long id);

    /*查询某个工作人员（商户）的商品列表*/
    List<OrderInfo> findByEndUserId(@Param("userId")Long userId,@Param("level")Integer level,@Param("status")Integer status);

    /*交易总额*/
    @Select("select sum(totalPrice) from order_info where status='完成' ")
    Double totalPrice();

    /*分类总销售额*/
    @Select("select e.name,sum(e.price) as price from (select a.totalPrice as price,d.name as name from order_info as a\n" +
            "join order_goods_rel as b on a.id = b.orderId\n" +
            "join goods_info as c on b.goodsId = c.id\n" +
            "left join type_info as d on c.typeId = d.id) as e\n" +
            "GROUP BY e.name")
    List<Map<String,Object>> getTypePrice();

    /*分类总销量*/
    @Select("select e.name,sum(e.count) as count from (select b.count as count,d.name as name from order_info as a\n" +
            "join order_goods_rel as b on a.id = b.orderId\n" +
            "join goods_info as c on b.goodsId = c.id\n" +
            "left join type_info as d on c.typeId = d.id) as e\n" +
            "GROUP BY e.name")
    List<Map<String,Object>> getTypeCount();


}
